1 //+-----------------------------------------------------------------------
3 // Copyright (c) Microsoft Corporation. All rights reserved.
6 // This file has all the code that detects whether the registry keys
7 // to disable xps documents and xapps are set.
9 // 2005/06/09 - akaza Created the file
10 // 2007/09/20 - [....]
11 // Ported Windows->DevDiv. See SourcesHistory.txt.
13 //------------------------------------------------------------------------
14 #include "Precompiled.hxx"
15 #include "DisableXappDocuments.hxx"
16 #include "UrlMonInterop.hxx"
17 #include "OleDocument.hxx"
18 #include "HostSupport.h"
19 #include "..\inc\registry.hxx"
21 // EXPLICIT definition because IE versions lesser than 7 will not have this value and will probabaly
24 #define URLMON_OPTION_FOR_BROWSERAPPSDOCUMENTS 0x10000010
25 #define URLACTION_WEB_BROWSER_APPLICATIONS_INTERNAL 0x00002400
26 #define URLACTION_XPS_DOCUMENTS_INTERNAL 0x00002401
27 #define URLACTION_LOOSE_XAML_INTERNAL 0x00002402
29 // generic function that checks presence or absence of a reg key in HKLM
30 // returns true if the key is present and its value is 1 , false otherwise
31 // pRegkeyLocationToCheck: The key in HKLM to open
32 // pRegKeyToExtract: The specific key to look for
33 BOOL
IsDisableKeySet(LPCTSTR pRegkeyLocationToCheck
, LPCTSTR pRegKeyToExtract
)
35 LONG lRet
= ERROR_SUCCESS
;
37 DWORD dwUnrestricted
= 0;
38 DWORD dwSize
= sizeof(dwUnrestricted
);
41 // throw exception in case pointer is null
42 Assert((pRegkeyLocationToCheck
!=NULL
) &&
43 (pRegKeyToExtract
!=NULL
));
45 // If it doesn't exist or if key exists and is 0 then return false
46 // if it exists and is set to 1, then return true
47 lRet
= RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
48 pRegkeyLocationToCheck
,
53 if (ERROR_SUCCESS
== lRet
)
55 lRet
= RegQueryValueEx(hKey
,
59 (LPBYTE
)&dwUnrestricted
,
63 return (ERROR_SUCCESS
== lRet
&& dwUnrestricted
== 1);
68 BOOL
IsMimeTypeDisabled(__in_ecount(INTERNET_MAX_URL_LENGTH
+1) LPOLESTR pUrl
, __in_ecount(1) COleDocument
* pOleDoc
)
70 MimeType mimeType
= pOleDoc
->GetCurrentMime();
71 DWORD dwAction
= URLACTION_WEB_BROWSER_APPLICATIONS_INTERNAL
;
76 case MimeType_Application
:
77 if (IsDisableKeySet(RegKey_WPF_Features
, RegValue_XBAPDisallow
))
82 if (IsDisableKeySet(RegKey_WPF_Features
, RegValue_XPSDocumentsDisallow
))
84 dwAction
= URLACTION_XPS_DOCUMENTS_INTERNAL
;
88 if (IsDisableKeySet(RegKey_WPF_Features
, RegValue_LooseXamlDisallow
))
90 dwAction
= URLACTION_LOOSE_XAML_INTERNAL
;
94 // The fact that the previous call returned false could mean one of two things
95 // either the key was available and value was set to zero (which should not happen)
96 // or the key does not exist.
97 // The key being set to zero could mean that we decided to disable this reg key or user did it
98 // to allow xapps to work. We should in the most case not encounter this.
99 // If the key was not present it could mean one of two things , either it was never there or
100 // we are on IE7. On IE 7 we want to run processUrlAction The following call does that for us
102 return !ProcessURLActionOnIE7(dwAction
,pUrl
,pOleDoc
);
107 // action indicates the mimetype we are dealing with
108 BOOL
ProcessURLActionOnIE7(DWORD action
, __in_ecount(INTERNET_MAX_URL_LENGTH
+1) LPOLESTR pUrl
, __in_ecount(1) COleDocument
* pOleDoc
)
112 LPBYTE dummyPtr
= new BYTE
[sizeof(DWORD
)];
114 Assert(pUrl
!= NULL
);
116 Assert(pOleDoc
!= NULL
);
118 // The following code calls into UrlMkGetSessionOption with the flag for URLMON_OPTION_USE_BROWSERAPPSDOCUMENTS
119 // if the return is E_INVALIDARGS then we are on a version of IE lesser than 7 else we get NOERROR.
120 // In the case where we get NOERROR we call ProcessURLAction with the appropriate flag for XAPPs or XPS
121 // depending on the value of the parameter passed in.
123 hr
= UrlMkGetSessionOption(URLMON_OPTION_FOR_BROWSERAPPSDOCUMENTS
, dummyPtr
, sizeof(DWORD
), &dwResult
, 0);
128 // this is the case where we are on a lower version of IE than version 7
130 if (E_INVALIDARG
== hr
)
135 // in this case we call ProcessURLAction depending on whether it is an application or a document
140 // at this time COM is already initialized so I do not
141 // call CoInitializeEx
142 // we do not really care about the return hr for this call since it returns
143 // either S_OK for allow or S_FALSE for ~S_ALLOW or E_OUTOFMEMORY
145 hr
= UrlmonInterop::ProcessUrlActionWrapper(action
, pUrl
, pOleDoc
,fAllow
);